
#include <types.h>
#include <osal/osal.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <api/libosd/osd_lib.h>
#include <api/libttx/lib_ttx.h>
#include <api/libsubt/lib_subt.h>

#include "copper_common/system_data.h"
#include "copper_common/com_api.h"

#include "osdobjs_def.h"
#include "win_com_menu_define.h"
#include "win_com_popup.h"
#include "menus_root.h"

#include "osd_config.h"
#include "string.id"
#include "images.id"
#include <api/libmp/mp_subtitle_api.h>

#include "win_com.h"
#include "win_subtitle.h"

#ifdef MP_SUBTITLE_SETTING_SUPPORT

/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER	win_subt_set_con;

extern CONTAINER subt_set_item_con1;
extern CONTAINER subt_set_item_con2;
extern CONTAINER subt_set_item_con3;
extern CONTAINER subt_set_item_con4;

extern TEXT_FIELD	 subt_set_title;

extern TEXT_FIELD subt_set_item_txtname1;
extern TEXT_FIELD subt_set_item_txtname2;
extern TEXT_FIELD subt_set_item_txtname3;
extern TEXT_FIELD subt_set_item_txtname4;

extern TEXT_FIELD subt_set_item_txtset1;
extern TEXT_FIELD subt_set_item_txtset2;
extern TEXT_FIELD subt_set_item_txtset3;
extern TEXT_FIELD subt_set_item_txtset4;

extern TEXT_FIELD subt_set_item_line1;
extern TEXT_FIELD subt_set_item_line2;
extern TEXT_FIELD subt_set_item_line3;
extern TEXT_FIELD subt_set_item_line4;



static VACTION subt_set_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT subt_set_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION subt_set_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT subt_set_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
#undef WIN_SH_IDX
#undef WIN_HL_IDX
#undef WIN_SL_IDX
#undef WIN_GRY_IDX 
#define WIN_SH_IDX	  WSTL_WIN_BODYLEFT_01_HD
#define WIN_HL_IDX	  WSTL_WIN_BODYLEFT_01_HD
#define WIN_SL_IDX	  WSTL_WIN_BODYLEFT_01_HD
#define WIN_GRY_IDX  WSTL_WIN_BODYLEFT_01_HD

#define CON_SH_IDX   WSTL_BUTTON_01_HD
#define CON_HL_IDX   WSTL_BUTTON_05_HD
#define CON_SL_IDX   WSTL_BUTTON_01_HD
#define CON_GRY_IDX  WSTL_BUTTON_07_HD

#define CON_HLSUB_IDX	WSTL_BUTTON_02_HD

#define TXT_SH_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_HL_IDX   WSTL_BUTTON_02_FG_HD
#define TXT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_GRY_IDX  WSTL_BUTTON_07_HD

#define SEL_SH_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_HL_IDX   WSTL_BUTTON_04_HD
#define SEL_SL_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_GRY_IDX  WSTL_BUTTON_07_HD

#define TITLE_SH_IDX	WSTL_WIN_TITLE_01_HD

#ifndef SD_UI

#define TITLE_L	20//229//232
#define TITLE_T	30//181//185
#define TITLE_W	550
#define TITLE_H	60

#undef W_L
#undef W_T
#undef W_W
#undef W_H
#undef CON_L
#undef CON_T
#undef CON_W
#undef CON_H
#undef CON_GAP

#define	W_L		TITLE_L //180
#define	W_T	TITLE_T//TITLE_T+TITLE_H
#define	W_W	TITLE_W
#define	W_H	260//200//218//134//90
#define CON_L	(W_L + 10)//(W_L + 4)
#define CON_T	(W_T + 2 + TITLE_H)//(W_T + 2)
#define CON_W	(W_W - 20)//(W_W - 8)
#define CON_H	40//42


#define CON_GAP	0

#define TXT_L_OF  	2
#define TXT_W  		((CON_W*5)/11)
#define TXT_H		CON_H//42//28
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  (TXT_L_OF + TXT_W)
#define SEL_W  		((CON_W*6)/11)
#define SEL_H		CON_H//42
#define SEL_T_OF	((CON_H - SEL_H)/2)

#else

#define TITLE_L	104//229//232
#define TITLE_T	100//181//185
#define TITLE_W	400
#define TITLE_H	40

#define	W_L		TITLE_L //180
#define	W_T	TITLE_T//TITLE_T+TITLE_H
#define	W_W	TITLE_W
#define	W_H	200//200//218//134//90
#define CON_L	(W_L + 10)//(W_L + 4)
#define CON_T	(W_T + 2 + TITLE_H)//(W_T + 2)
#define CON_W	(W_W - 20)//(W_W - 8)
#define CON_H	32//42


#define CON_GAP	0

#define TXT_L_OF  	2
#define TXT_W  		((CON_W*5)/11)
#define TXT_H		CON_H//42//28
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  (TXT_L_OF + TXT_W)
#define SEL_W  		((CON_W*6)/11)
#define SEL_H		CON_H//42
#define SEL_T_OF	((CON_H - SEL_H)/2)

#endif


#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,hl,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    subt_set_item_con_keymap,subt_set_item_con_callback,  \
    conobj, ID,1)
    
#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT| C_ALIGN_VCENTER, 0,0,resID,NULL)

#define LDEF_TXTSET(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, SEL_SH_IDX,SEL_HL_IDX,SEL_SL_IDX,SEL_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 20,0,resID,str)
    
#define LDEF_MENU_ITEM_SEL(root,varCon,nxtObj,varTxt,varTxtset,ID,IDu,IDd,\
						l,t,w,h,resIDname,resIDset,setstr) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HL_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varTxtset,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resIDname)    \
    LDEF_TXTSET(&varCon,varTxtset,  NULL        ,1,1,1,1,1,l + SEL_L_OF ,t + SEL_T_OF,SEL_W-1,SEL_H,resIDset,setstr)


#define LDEF_MENU_ITEM_TXT(root,varCon,nxtObj,varTxt,ID,IDu,IDd,\
						l,t,w,h,resID) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HLSUB_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,NULL,l,t + TXT_T_OF,W_W-8,TXT_H,resID)
    

DEF_TEXTFIELD(subt_set_title,&win_subt_set_con,&subt_set_item_con1,C_ATTR_ACTIVE,0, \
    0,0,0,0,0,TITLE_L,TITLE_T ,TITLE_W,TITLE_H, TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,RS_SUBT_SETTING,NULL)
    
LDEF_MENU_ITEM_SEL(win_subt_set_con,subt_set_item_con1,&subt_set_item_con2,subt_set_item_txtname1,subt_set_item_txtset1, 1, 4, 2, \
		CON_L, CON_T + (CON_H + CON_GAP)*0, CON_W, CON_H, RS_SUBT_SETTING_FONT_SIZE, 0, display_strs[0])

LDEF_MENU_ITEM_SEL(win_subt_set_con,subt_set_item_con2,&subt_set_item_con3,subt_set_item_txtname2,subt_set_item_txtset2, 2, 1, 3, \
		CON_L, CON_T + (CON_H + CON_GAP)*1, CON_W, CON_H, RS_SUBT_SETTING_FG_COLOR, 0, display_strs[1])

LDEF_MENU_ITEM_SEL(win_subt_set_con,subt_set_item_con3,&subt_set_item_con4,subt_set_item_txtname3,subt_set_item_txtset3, 3, 2, 4, \
		CON_L, CON_T + (CON_H + CON_GAP)*2, CON_W, CON_H, RS_SUBT_SETTING_BG_COLOR, 0, display_strs[2])

LDEF_MENU_ITEM_SEL(win_subt_set_con,subt_set_item_con4,NULL,subt_set_item_txtname4,subt_set_item_txtset4, 4, 3, 1, \
		CON_L, CON_T + (CON_H + CON_GAP)*3, CON_W, CON_H, RS_SUBT_SETTING_LOCATION, 0, display_strs[3])


DEF_CONTAINER(win_subt_set_con,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, W_L,W_T,W_W,W_H, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    subt_set_con_keymap,subt_set_con_callback,  \
    (POBJECT_HEAD)&subt_set_title, 1,0)

/*******************************************************************************
*	Local functions & variables define
*******************************************************************************/
CONTAINER* subt_set_items[] =
{
	&subt_set_item_con1,
	&subt_set_item_con2,
	&subt_set_item_con3,
	&subt_set_item_con4,
};

POBJECT_HEAD subt_set_item_name[] =
{
	(POBJECT_HEAD)&subt_set_item_txtname1,
	(POBJECT_HEAD)&subt_set_item_txtname2,
	(POBJECT_HEAD)&subt_set_item_txtname3,
	(POBJECT_HEAD)&subt_set_item_txtname4,
};

POBJECT_HEAD subt_set_item_set[] =
{
	(POBJECT_HEAD)&subt_set_item_txtset1,
	(POBJECT_HEAD)&subt_set_item_txtset2,
	(POBJECT_HEAD)&subt_set_item_txtset3,
	(POBJECT_HEAD)&subt_set_item_txtset4,
};

enum{
MENU_SUBT_SET_FONT_SIZE=1,
MENU_SUBT_SET_FG_COLOR,
MENU_SUBT_SET_BG_COLOR,
MENU_SUBT_SET_POSITION,
};

#define MAX_SUBT_COLOR_NUM	7
#define MAX_SUBT_FONT_SIZE	3
#define MAX_SUBT_POSITION_NUM		101 //0~100

static ID	subt_set_timer = OSAL_INVALID_ID;
UINT32 SUBT_SET_TIMER_TIME = 5*1000; //5s for subtitle setting menu
#define SUBT_SET_TIMER_NAME 	"vol"

static UINT8 subt_set_menu_layer = 0;//record the menu layer, val:0/1

/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/

static void subt_set_timer_func(UINT unused)
{
	if(OSAL_INVALID_ID==subt_set_timer)
		return;
	
	UINT32 hkey,i;
	api_stop_timer(&subt_set_timer);
	ap_vk_to_hk(0, V_KEY_EXIT, &hkey);
	for(i=0;i<=subt_set_menu_layer;i++)
	{
		ap_send_msg(CTRL_MSG_SUBTYPE_KEY, hkey, TRUE); // send key instead of sending message
		//ap_send_msg(CTRL_MSG_SUBTYPE_CMD_EXIT, 1, TRUE);
	}
}

static void subt_set_timer_refresh()
{
	if(OSAL_INVALID_ID==subt_set_timer)
		return;
	
	api_stop_timer(&subt_set_timer);		 
	subt_set_timer = api_start_timer(SUBT_SET_TIMER_NAME,SUBT_SET_TIMER_TIME,subt_set_timer_func);

}

static void win_subt_set_fontsize_string(INT8 input)
{
	INT8 temp[12];
	
	if(SUBT_FONT_SIZE_NORMAL == input)
		sprintf(temp, "Normal", input);
	else if(SUBT_FONT_SIZE_SMALL == input)
		sprintf(temp, "Small", input);
	else
		sprintf(temp, "Big", input);	

	ComAscStr2Uni(temp, display_strs[0]);
}

static void win_subt_set_fg_color_string(INT8 input)
{
	INT8 temp[12];
	
	if(SUBT_COLOR_BLACK == input)
		sprintf(temp, "Black", input);
	else if(SUBT_COLOR_RED == input)
		sprintf(temp, "Red", input);
	else if(SUBT_COLOR_GREEN== input)
		sprintf(temp, "Green", input);
	else if(SUBT_COLOR_YELLOW== input)
		sprintf(temp, "Yellow", input);
	else if(SUBT_COLOR_BLUE== input)
		sprintf(temp, "Blue", input);
	else if(SUBT_COLOR_WHITE== input)
		sprintf(temp, "White", input);
	else
		sprintf(temp, "Transparent", input);
	
	ComAscStr2Uni(temp, display_strs[1]);
}

static void win_subt_set_bg_color_string(INT8 input)
{
	INT8 temp[12];
	
	if(SUBT_COLOR_BLACK == input)
		sprintf(temp, "Black", input);
	else if(SUBT_COLOR_RED == input)
		sprintf(temp, "Red", input);
	else if(SUBT_COLOR_GREEN== input)
		sprintf(temp, "Green", input);
	else if(SUBT_COLOR_YELLOW== input)
		sprintf(temp, "Yellow", input);
	else if(SUBT_COLOR_BLUE== input)
		sprintf(temp, "Blue", input);
	else if(SUBT_COLOR_WHITE== input)
		sprintf(temp, "White", input);
	else
		sprintf(temp, "Transparent", input);
	
	ComAscStr2Uni(temp, display_strs[2]);
}

static void win_subt_set_position_string(INT8 input)
{
	INT8 temp[12];

	INT16 select_disp = 50-input;//0~100  => +50~0~-50
	if(0== select_disp)
		sprintf(temp,"Buttom",select_disp);
	else
		sprintf(temp,"%d", select_disp);
						
	ComAscStr2Uni(temp, display_strs[3]);
}


static VACTION subt_set_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
	case V_KEY_RIGHT:
		act = VACT_INCREASE;
		break;		
	case V_KEY_LEFT:		
		act = VACT_DECREASE;
		break;		
	case V_KEY_ENTER:
		act = VACT_ENTER;
		break;		
	default:	
		act = VACT_PASS;
		break;
	}

	subt_set_timer_refresh();
	
	return act;

}

void win_subt_set_enter_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	OSD_RECT rect;
	COM_POP_LIST_PARAM_T param;
	
	rect.uLeft=CON_L+TXTS_L_OF;
	rect.uWidth=TXTS_W;
	rect.uHeight=250;
	param.selecttype = POP_LIST_SINGLESELECT;
	switch(id)
	{
		case MENU_SUBT_SET_FONT_SIZE:
			#ifndef SD_UI
			rect.uHeight = 300;
			rect.uTop=CON_T + (CON_H + CON_GAP)*1;
			#else
			rect.uHeight = 180;
			rect.uTop=CON_T + (CON_H + CON_GAP)*1;
			#endif
			
			param.cur=p_sys_data->ext_subt_param.font_size;
			subt_set_menu_layer+=1;//enter second layer
			p_sys_data->ext_subt_param.font_size = win_com_open_sub_list(POP_LIST_SUBT_SET,&rect,&param);
			subt_set_menu_layer-=1;//leve second layer
			win_subt_set_fontsize_string(p_sys_data->ext_subt_param.font_size);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_FG_COLOR:
			#ifndef SD_UI
			rect.uHeight = 300;
			rect.uTop=CON_T + (CON_H + CON_GAP)*2;
			#else
			rect.uHeight = 180;
			rect.uTop=CON_T + (CON_H + CON_GAP)*2;
			#endif
			
			param.cur=p_sys_data->ext_subt_param.fg_color;
			subt_set_menu_layer+=1;//enter second layer
			p_sys_data->ext_subt_param.fg_color = win_com_open_sub_list(POP_LIST_SUBT_SET,&rect,&param);
			subt_set_menu_layer-=1;//leve second layer
			win_subt_set_fg_color_string(p_sys_data->ext_subt_param.fg_color);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_BG_COLOR:
			#ifndef SD_UI
			rect.uHeight = 300;
			rect.uTop=CON_T + (CON_H + CON_GAP)*3;
			#else
			rect.uHeight = 180;
			rect.uTop=CON_T + (CON_H + CON_GAP)*3;
			#endif
			
			param.cur=p_sys_data->ext_subt_param.bg_color;
			subt_set_menu_layer+=1;//enter second layer
			p_sys_data->ext_subt_param.bg_color = win_com_open_sub_list(POP_LIST_SUBT_SET,&rect,&param);
			subt_set_menu_layer-=1;//leve second layer
			win_subt_set_bg_color_string(p_sys_data->ext_subt_param.bg_color);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_POSITION:
			#ifndef SD_UI
			rect.uHeight = 300;
			rect.uTop=CON_T + (CON_H + CON_GAP)*4;
			#else
			rect.uHeight = 180;
			rect.uTop=CON_T + (CON_H + CON_GAP)*4;
			#endif
			
			param.cur=p_sys_data->ext_subt_param.y_offset;
			subt_set_menu_layer+=1;//enter second layer
			p_sys_data->ext_subt_param.y_offset = win_com_open_sub_list(POP_LIST_SUBT_SET,&rect,&param);
			subt_set_menu_layer-=1;//leve second layer
			win_subt_set_position_string(p_sys_data->ext_subt_param.y_offset);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;	
	}

}

void win_subt_set_left_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	switch(id)
	{
		case MENU_SUBT_SET_FONT_SIZE:
			if(SUBT_FONT_SIZE_NORMAL==p_sys_data->ext_subt_param.font_size)
			{
				p_sys_data->ext_subt_param.font_size=SUBT_FONT_SIZE_BIG;
			}
			else
			{
				p_sys_data->ext_subt_param.font_size--;
			}
			win_subt_set_fontsize_string(p_sys_data->ext_subt_param.font_size);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_FG_COLOR:
			if(SUBT_COLOR_BLACK==p_sys_data->ext_subt_param.fg_color)
			{
				p_sys_data->ext_subt_param.fg_color=SUBT_COLOR_TRANSPARENT;
			}
			else
			{
				p_sys_data->ext_subt_param.fg_color--;
			}
			win_subt_set_fg_color_string(p_sys_data->ext_subt_param.fg_color);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_BG_COLOR:
			if(SUBT_COLOR_BLACK==p_sys_data->ext_subt_param.bg_color)
			{
				p_sys_data->ext_subt_param.bg_color=SUBT_COLOR_TRANSPARENT;
			}
			else
			{
				p_sys_data->ext_subt_param.bg_color--;
			}
			win_subt_set_bg_color_string(p_sys_data->ext_subt_param.bg_color);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_POSITION:
			if(0==p_sys_data->ext_subt_param.y_offset)
			{
				p_sys_data->ext_subt_param.y_offset=MAX_SUBT_POSITION_NUM-1;
			}
			else
			{
				p_sys_data->ext_subt_param.y_offset--;
			}
			win_subt_set_position_string(p_sys_data->ext_subt_param.y_offset);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;	
	}
}

void win_subt_set_right_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	switch(id)
	{
		case MENU_SUBT_SET_FONT_SIZE:
			if(SUBT_FONT_SIZE_BIG==p_sys_data->ext_subt_param.font_size)
			{
				p_sys_data->ext_subt_param.font_size=SUBT_FONT_SIZE_NORMAL;
			}
			else
			{
				p_sys_data->ext_subt_param.font_size++;
			}
			win_subt_set_fontsize_string(p_sys_data->ext_subt_param.font_size);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_FG_COLOR:
			if(SUBT_COLOR_TRANSPARENT==p_sys_data->ext_subt_param.fg_color)
			{
				p_sys_data->ext_subt_param.fg_color=SUBT_COLOR_BLACK;
			}
			else
			{
				p_sys_data->ext_subt_param.fg_color++;
			}
			win_subt_set_fg_color_string(p_sys_data->ext_subt_param.fg_color);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_BG_COLOR:
			if(SUBT_COLOR_TRANSPARENT==p_sys_data->ext_subt_param.bg_color)
			{
				p_sys_data->ext_subt_param.bg_color=SUBT_COLOR_BLACK;
			}
			else
			{
				p_sys_data->ext_subt_param.bg_color++;
			}
			win_subt_set_bg_color_string(p_sys_data->ext_subt_param.bg_color);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_SUBT_SET_POSITION:
			if((MAX_SUBT_POSITION_NUM-1)==p_sys_data->ext_subt_param.y_offset)
			{
				p_sys_data->ext_subt_param.y_offset=0;
			}
			else
			{
				p_sys_data->ext_subt_param.y_offset++;
			}
			win_subt_set_position_string(p_sys_data->ext_subt_param.y_offset);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;	
	}
}

static PRESULT subt_set_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact,input;
	UINT8	id = OSD_GetObjID(pObj);
	SYSTEM_DATA* p_sys_data=sys_data_get();

	switch(event)
	{	
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_ENTER)
		{
			win_subt_set_enter_key(pObj,id);
		}
		else if(unact == VACT_DECREASE)
		{
			win_subt_set_left_key(pObj,id);
		}
		else if(unact == VACT_INCREASE)
		{
			win_subt_set_right_key(pObj,id);
		}
		ret = PROC_LOOP;
		break;
	}
	return ret;

}

static VACTION subt_set_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
		case V_KEY_EXIT:
		case V_KEY_MENU:
		case V_KEY_BLUE:
			act = VACT_CLOSE;
			break;		
		case V_KEY_ENTER:
			act = VACT_ENTER;
			break;		
		default:	
			act = OSD_ContainerKeyMap(pObj,key);
	}

	subt_set_timer_refresh();
	
	return act;
}

static PRESULT subt_set_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT32 i;
	BOOL subt_flag;
	CONTAINER* cont = (CONTAINER*)pObj;
	UINT8	id = OSD_GetObjID(pObj);
	SYSTEM_DATA* p_sys_data;
	
	switch(event)
	{
	case EVN_PRE_OPEN:	
		p_sys_data=sys_data_get();
		win_subt_set_fontsize_string(p_sys_data->ext_subt_param.font_size);
		win_subt_set_fg_color_string(p_sys_data->ext_subt_param.fg_color);
		win_subt_set_bg_color_string(p_sys_data->ext_subt_param.bg_color);
		win_subt_set_position_string(p_sys_data->ext_subt_param.y_offset);
		SUBT_SET_TIMER_TIME = p_sys_data->osd_set.time_out;
		if(SUBT_SET_TIMER_TIME == 0 || SUBT_SET_TIMER_TIME>10)
			SUBT_SET_TIMER_TIME = 5;
		SUBT_SET_TIMER_TIME *= 1000;		
		break;
	
	case EVN_POST_OPEN:
		subt_set_timer = api_start_timer(SUBT_SET_TIMER_NAME, SUBT_SET_TIMER_TIME,subt_set_timer_func);
		break;

	case EVN_MSG_GOT:
#ifdef USB_MP_SUPPORT
		if(param1 == CTRL_MSG_SUBTYPE_STATUS_VIDEO_OVER)
		{
			ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_VIDEO_OVER,0,TRUE);
			subt_set_timer_func(0);
		}
#endif
		break;
		
	case EVN_PRE_CLOSE:
		unact = (VACTION)(param1>>16);
		ret = PROC_PASS;	
		break;

	case EVN_POST_CLOSE:
		api_stop_timer(&subt_set_timer);		
        	sys_data_save(1);
		break;
	}
	return ret;
}

UINT8 win_subt_set_get_num()
{
	UINT8 ID=OSD_GetFocusID((POBJECT_HEAD)&win_subt_set_con);
	SYSTEM_DATA* p_sys_data=sys_data_get();
	UINT8 num=0;
	
	switch(ID)
	{
		case MENU_SUBT_SET_FONT_SIZE:
			num=MAX_SUBT_FONT_SIZE;
			break;
		case MENU_SUBT_SET_FG_COLOR:
			num=MAX_SUBT_COLOR_NUM;
			break;
		case MENU_SUBT_SET_BG_COLOR:
			num=MAX_SUBT_COLOR_NUM;
			break;
		case MENU_SUBT_SET_POSITION:
			num=MAX_SUBT_POSITION_NUM;
			break;
	}
	return num;
}

VACTION comlist_menu_subt_set_listkeymap(POBJECT_HEAD pObj, UINT32 vkey)
{
	VACTION act = VACT_PASS;

	switch(vkey)
	{
	case V_KEY_UP:
		act = VACT_CURSOR_UP;
		break;        
	case V_KEY_DOWN:
		act = VACT_CURSOR_DOWN;
		break; 
	case V_KEY_P_UP:
		act = VACT_CURSOR_PGUP;
		break; 
	case V_KEY_P_DOWN:
		act = VACT_CURSOR_PGDN;
		break; 
	case V_KEY_ENTER:
		act = VACT_SELECT;
		break;
	}
			
	subt_set_timer_refresh();
	
	return act;    
}

VACTION comlist_menu_subt_set_winkeymap(POBJECT_HEAD pObj, UINT32 vkey)
{
	PRESULT ret = VACT_PASS;
	switch(vkey)
	{
	case V_KEY_MENU:
	case V_KEY_EXIT:
	    ret = VACT_CLOSE;              
	}

	//libc_printf("winkey:%d\n",vkey);
	subt_set_timer_refresh();
	
	return ret;
}

PRESULT comlist_menu_subt_set_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	INT16 i,wTop;
	UINT8 id;
	char str_len;
    	OBJLIST* ol;
	INT8 temp[4];
	
	PRESULT cbRet = PROC_PASS;

    	ol = (OBJLIST*)pObj;
	
	if(event==EVN_PRE_DRAW)
	{
		id=OSD_GetFocusID((POBJECT_HEAD)&win_subt_set_con);
		switch(id)
		{
			case MENU_SUBT_SET_FONT_SIZE:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
			    		if(SUBT_FONT_SIZE_NORMAL ==  i+wTop)
						sprintf(temp, "Normal",  i+wTop);
					else if(SUBT_FONT_SIZE_SMALL ==  i+wTop)
						sprintf(temp, "Small",  i+wTop);
					else
						sprintf(temp, "Big",  i+wTop);

					win_comlist_set_str(i + wTop,temp,NULL,0);
			    	}
				break;
			case MENU_SUBT_SET_FG_COLOR:
			case MENU_SUBT_SET_BG_COLOR:	
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
			    		if(SUBT_COLOR_BLACK ==  i+wTop)
						sprintf(temp, "Black",  i+wTop);
					else if(SUBT_COLOR_RED ==  i+wTop)
						sprintf(temp, "Red",  i+wTop);
					else if(SUBT_COLOR_GREEN==  i+wTop)
						sprintf(temp, "Green",  i+wTop);
					else if(SUBT_COLOR_YELLOW==  i+wTop)
						sprintf(temp, "Yellow",  i+wTop);
					else if(SUBT_COLOR_BLUE==  i+wTop)
						sprintf(temp, "Blue",  i+wTop);
					else if(SUBT_COLOR_WHITE==  i+wTop)
						sprintf(temp, "White",  i+wTop);
					else
						sprintf(temp, "Transparent",  i+wTop);

					win_comlist_set_str(i + wTop,temp,NULL,0);
			    	}
				break;
			case MENU_SUBT_SET_POSITION:
			    	wTop = OSD_GetObjListTop(ol);
			    	for(i=0;i<ol->wDep && (i+wTop)<ol->wCount;i++)
			    	{
			    		INT16 select_disp = 50-(i+wTop);//0~100  => +50~0~-50
			    		if(0== select_disp)
						sprintf(temp,"Buttom",i+wTop);
					else
						sprintf(temp,"%d", select_disp);
					
					win_comlist_set_str(i + wTop,temp,NULL,0);
			    	}
				break;
		}
	}
	else if(event == EVN_POST_CHANGE)
	{
		cbRet = PROC_LEAVE;
	}

	return cbRet;
}
#endif

